import socket
import json


class ChatClient(object):
    def __init__(self):
        self.sock = socket.socket()
        self.sock.connect(('localhost', 9999))



    def msgsnd(self):
        self.name = input("input your name: ")
        while True:

            msg_content = input(">>: ")
            if len(msg_content) == 0:
                continue
            msg = {
                'user': self.name,
                'content': msg_content
            }
            self.sock.send(json.dumps(msg).encode())


    def msgrev(self):
        while True:
            data = self.sock.recv(1024)
            msg = json.loads(data.decode())
            print("%s: %s" %(msg['user'], msg['content']))
